package com.example.imagepicker.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.example.imagepicker.adapter.MainGVAdapter;
import com.example.imagepicker.model.Photo;
import com.tool.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 主页面，可跳转至相册选择照片，并在此页面显示所选择的照片。
 * Created by hanj on 14-10-13.
 */
public class MainActivity extends Activity {
    private MainGVAdapter adapter;
    private List<Photo> imagePathList;//// 0未选中  1选中（待上传） 2上传成功  3上传失败

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        //获取屏幕像素
//        ScreenUtils.initScreen(this);
//        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(MainActivity.this));
//
//        TextView titleTV = (TextView) findViewById(R.id.topbar_title_tv);
//        Button selectImgBtn = (Button) findViewById(R.id.main_select_image);
//        GridView mainGV = (GridView) findViewById(R.id.main_gridView);
//
//        titleTV.setText(R.string.app_name);
//        imagePathList = new ArrayList<Photo>();
//        adapter = new MainGVAdapter(this, imagePathList);
//        mainGV.setAdapter(adapter);
//
//        selectImgBtn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                //跳转至最终的选择图片页面
//                Intent intent = new Intent(MainActivity.this, PhotoWallActivity.class);
//                //intent.putExtra("LastmaxCount", 0);//不传默认最近显示99 传值-1 则为最近显示 所有图片
//                //intent.putExtra("NeedCount", 5);//可以选中图片的位数  传值小于或等于0或不传 视为无限制
//                startActivityForResult(intent, requestCode_phone);
//            }
//        });
    }

    private final static int requestCode_phone = 0x01; 
    /* (非 Javadoc)
     * Description:
     * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK&&requestCode==requestCode_phone){
            
            ArrayList<String> paths = data.getStringArrayListExtra("paths");
           
            
            List<Photo> list = new ArrayList<Photo>();
            Photo p = null;
            for(String s:paths){
                p = new Photo(s);
                p.setStatus(1); // 0未选中  1选中（待上传） 2上传成功  3上传失败
                list.add(p);
            }
            Photo photo_add = new Photo("drawable:");
            photo_add.setStatus(0);
            list.add(photo_add);
            
            Log.i("paths=",paths.size()+"");
            imagePathList.clear();
            imagePathList.addAll(list);
            adapter.notifyDataSetChanged();
            
        }
    }
    
}
